package com.xsqf.jt808.common.vo.req.server;

import com.xsqf.jt808.common.config.JT808Const;
import com.xsqf.jt808.common.vo.DataPacket;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * PassthroughPack
 * 数据透传包
 * @author
 * @date 2020/6/3 15:23
 */
@Data
@NoArgsConstructor
public class PassthroughPack extends DataPacket {

    public PassthroughPack(ByteBuf byteBuf) {
        super(byteBuf);
    }

    //GNSS模块详细定位数据
    public static final byte GNSSLocation = 0x00;
    //道路运输证IC卡信息上传消息为64Byte，下传消息为24Byte。道路运输证IC卡认证透传超时时间为30s。超时后，不重发。
    public static final byte ICCardInfo = 0x0B;
    //串口1透传消息
    public static final byte SerialPortOne = 0x41;
    //串口2透传消息
    public static final byte SerialPortTow = 0x42;
    //用户自定义透传 0xF0 - 0xFF
    public static final byte Custom = (byte)0xFF;

    @ApiModelProperty(value = "透传消息类型")
    private byte type;

    @ApiModelProperty(value = "透传消息内容")
    private String content;

    @Override
    public ByteBuf toByteBufMsg(){
        ByteBuf bb = super.toByteBufMsg();
        bb.writeByte(type);
        bb.writeBytes(content.getBytes(JT808Const.DEFAULT_CHARSET));
        return bb;
    }

    @Override
    public void parseBody() {
        ByteBuf bb = this.payload;
        this.setType(bb.readByte());
        this.setContent(readString(bb.readableBytes()));

    }

}
